#pragma once
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <deque>
///////////////////////////////////////////////////////////////////////////////////////////////
#define		MENU_NORMAL			0X00000000
#define		MENU_POPUPED		0X80000000
#define		MENU_CHILD			0X40000000
#define		MENU_PARENT			0X20000000
#define		MENU_ROOT			0X10000000
#define		MENU_SELECTED		0X08000000
#define		MENU_TIMERTRACK		0X04000000
#define		MENU_SELBORDER		0X02000000
#define		MENU_TIMERDESTROY	0X01000000
#define		MENU_OWNERDRAW		0X00800000
#define		MENU_DESTROYED		0X00400000

#define		SELNONE				-1
#define		FINDNONE			-5
#define		TIMERTRACK			1
#define		TIMERDESTROY		2

#ifndef	ZLTEXT
#define	ZLTEXT(s) s
#endif
///////////////////////////////////////////////////////////////////////////////////////////////
const long __MENU_EDGE__ = 3;
const TCHAR __UWPMenu9_clsname__[]={_T("@MyMenu9")};
class UWNDPLUS9_API __declspec(novtable) UWPMenu9  
{
class __declspec(novtable) ITEM
{
public:
	TCHAR	m_strText[64];
	RECT	rtItem;
	long	Width,Height;
	int		m_nHeight;
	UWPMenu9*PopupMenu;
	UINT	m_uID,m_ulData,m_uFlags;
	ITEM(UINT uFlags,UINT ulData,UINT uID,LPCTSTR szText):Width(0),Height(0),
		m_nHeight(0),m_uID(uID),m_ulData(ulData),m_uFlags(uFlags),PopupMenu(NULL)
	{
		memset(&rtItem,0,sizeof(rtItem));
		memset(m_strText,0,sizeof(m_strText));
		lstrcpyn(m_strText,szText,64);
	}
	void SetText(LPCTSTR szText)
	{
		lstrcpyn(m_strText,szText,64);
	}
};
typedef struct tagDRAWITEMSTRUCTPRO
{
	HDC		hDC;
	RECT	rect;
	LPCTSTR	lpcStr;
	UINT	uFlags,ulData;
}DRAWITEMSTRUCTPRO,*LPDRAWITEMSTRUCTPRO;
typedef std::deque<ITEM> DEQUEITEM;
public:
	UWPMenu9(void);
	~UWPMenu9(void);
//static methods and data:
	//use it!
	void	MapMenuFrom(CMenu*pMenu);
	//icon
	BOOL	SetMenuIcon(UINT nItem,int nNewIconID,UINT uFlag=MF_BYPOSITION);

	void	SetState(UINT uFlag,int bSet);
	void	GetMenuCXY( int& nMenuWidth, int& nMenuHeight );
	BOOL	GetMenuData( int nItem, UINT *pulData, UINT uFlag = MF_BYPOSITION ) const;

	BOOL	SetSubMenu( int nItem, UWPMenu9 *pPopupMenu, UINT uFlag = MF_BYPOSITION );
	BOOL	SetMenuData( int nItem, UINT ulData, UINT uFlag = MF_BYPOSITION );

	void	AppendMenu(LPCTSTR pszName,UINT	uID,UINT ulData=0,UINT uFlags=0);								// Append a New Menu Item
	BOOL	AppendPopup(LPCTSTR pszName, UWPMenu9 *pPopupMenu, UINT uID = 0, UINT ulData = 0, UINT uFlags = 0 );	// Append a Popup Item in Menu
	
	UINT	TrackPopMenu(long x,long y,HWND hwndParent,UINT uFlag = 0 );							// Display and Track Menu		


	void	DestroyMenu		( void );
	void	DestroyAllPop	( void );
	void	DestroyAllMenu	( void );

	HWND	m_hMenu,m_hWndParent;

	void	OnPaint(HWND hWnd,HDC hDC);
	void	OnKeyDown(HWND hWnd,UINT nChar,UINT nRepCnt,UINT nFlags);
	void	OnMouseMove(HWND hWnd,short x,short y);
	void	OnTimer(HWND hWnd,WORD uID);
	void	OnLButtonDown(HWND hWnd,short x,short y);
	void	OnLButtonUp(HWND hWnd,short x,short y);
	void	OnRButtonDown(HWND hWnd,short x,short y);
protected:
	BOOL			IsEffectItem	( void );
	BOOL			GetState		( UINT uFlag ) const;

	void			ResetDispPoint	( int& x, int& y );
	void			TimerDelay		( HWND hWnd );

	int				GetNewSel		( short x, short y );
	int				GetItemIndex	( int nItem, UINT uFlag ) const;
	UWPMenu9*		GetNewMenu		( HWND hWnd, short x, short y );

	void			RedrawItem		( HWND hWnd, int nCurSel, int nOldSel );
	void			DrawItemAnimation( LPDRAWITEMSTRUCTPRO lpdisp );
private:
	void	Initialize(void);

	void	DrawItem(LPDRAWITEMSTRUCTPRO lpdisp);
	void	DrawItemIcon(LPDRAWITEMSTRUCTPRO lpdisp);
	void	MeasureItem(LPMEASUREITEMSTRUCT lpmis,HDC hDC);
	void	DrawMenuBkgnd(HWND hWnd,HDC hDC);
	void	DrawItemText(LPDRAWITEMSTRUCTPRO lpdisp);
	void	DrawItemBkgnd(LPDRAWITEMSTRUCTPRO lpdisp);
protected:
	int		m_nMenuWidth,m_nMenuHeight;
	int		m_nMenuItemHeight;					
	int		m_nCurPop,m_nCurSel;
	UWPMenu9	*m_pParent;								
	UINT		m_uMenuFlag;
	DEQUEITEM	m_qMenuItem;	// Save Menu Item Informations
	int			m_nIconSize;
public:
	BOOL	frameModule;
	UINT	MenuAniType,ItemAniType;
	int     m_nMenuYAxis;

};
LRESULT CALLBACK AfxMenuWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
